//
//  UIBarButtonItem+Extension.swift
//  sinaweibo
//
//  Created by WGP on 16/4/12.
//  Copyright © 2016年 WGP. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
//    便利构造函数最终需要调用一个指定构造函数
    
    convenience init(imageName: String, target: AnyObject?, action: Selector)
    {
//        创建按钮
        let button = UIButton()
        
//        设置按钮
        button.setImage(UIImage(named: imageName), forState: .Normal)
        button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: .Highlighted)
        button.sizeToFit()
        
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        self.init(customView: button)
    }

}
